<%@tag import="java.sql.Connection"%>
<%@tag import="by.epam.communalservices.dao.jdbc.JdbcDaoJkhTeam"%>
<%@tag import="by.epam.communalservices.entity.JkhTeam"%>
<%@tag import="by.epam.communalservices.utils.Staff"%>
<%@tag import="java.util.List"%>

<%@ attribute name="id" required="true"%>
<%@ attribute name="edit" type="java.lang.Boolean"%>
<%@ attribute name="link" type="java.lang.Boolean"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<%
    Staff staff = new Staff((Connection) request.getSession().getAttribute("currentConnection"));
    List<JkhTeam> teamList = staff.getWorkerStaff(Long.parseLong(getJspContext().getAttribute("id").toString()));
    getJspContext().setAttribute("teamList",teamList);
    
%>

<c:choose>
	<c:when test="${link}">
		<c:forEach items="${pageScope.teamList}" var="item">
			<p>
			<c:if test="${edit or (sessionScope.currentUser.id eq item.idOwner)}">
			<a href="worker_edit?id=${id}&remove=${item.id}" onclick="if(confirm('Уверены?')) return true else return false;"
				style='color:red;float:right;position:relative;'><font color=red>remove</font></a>
			</c:if>
			<c:out value="${item.id}"/>.
			<a href="team_edit?id=${item.id}"><c:out value="${item.surname}"/> <c:out value="${item.name}"/></a>
			</p>
		</c:forEach>
	</c:when>
	<c:otherwise>
		<c:forEach items="${pageScope.teamList}" var="item">
	  		<p>
			<c:if test="${edit}">
			<a href="worker_edit?id=${id}&remove=${item.id}" onclick="if(confirm('Уверены?')) return true else return false;"
				style='color:red;float:right;position:relative;'><font color=red>remove</font></a>
			</c:if>
			<c:out value="${item.id}"/>.
			<c:out value="${item.surname}"/> <c:out value="${item.name}"/> <c:out value="${item.patronymic}"/>
			</p>
		</c:forEach>
	</c:otherwise>
</c:choose>

